﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//using System.Xml.Linq;
using System.Collections.Generic;

using YouHP.BLL;
using YouHP.Model;
using YouHP.Model.Group;
using YouHP.Utility;

namespace web.admin
{
    public partial class ActiveUserAdd : System.Web.UI.Page
    {
        private RecommendUserBLL recommendUserBLL = RecommendUserBLL.Instance;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }

        protected void CancelButton_click(object sender, EventArgs e)
        {

        }
        protected void InsertButton_click(object sender, EventArgs e)
        {
            List<ActiveUserInfo> info = validateForm(this.activeUserInfo);

            if (info != null)
            {
                if (recommendUserBLL.ActiveUserAdd(info))
                {
                    Response.Redirect("ActiveUserList.aspx");
                }
            }
            else
            {
                Response.Write("<script>alert('User is not exist');</script>");
            }

        }
        protected void DataBound(object sender, EventArgs e)
        {

        }
        private List <ActiveUserInfo> validateForm(DetailsView formViewCtl)
        {
            List <ActiveUserInfo> info = new List<ActiveUserInfo>();
            int userid = 0;

            //info.IsNews = Convert.ToInt32(this.GroupId.Text);
            string tmpStr = ((TextBox)formViewCtl.FindControl("用户名")).Text.Trim();
            string[] tmpStr1 = tmpStr.Split(';');
            for (int i = 0; i < tmpStr1.Length; i++)
            {
                if (UserBLL.Instance.CheckExsitUserName(tmpStr1[i]))
                {
                    ActiveUserInfo tmpActiveUserInfo = new ActiveUserInfo();
                    userid = UserBLL.Instance.GetUserIdByUserName(tmpStr1[i]);
                    tmpActiveUserInfo.userid = userid;
                    tmpActiveUserInfo.username = tmpStr1[i];
                    tmpActiveUserInfo.IsRecommended = false;
                    info.Add(tmpActiveUserInfo);
                }
            }

            return info;
            //if ((userIsExist))
            //{
            //    return info;
            //}
            //else
            //{
            //    return (List <ActiveUserInfo>)null;
            //}
        }
    }
}
